<!-- 分类展示：second-one 风格  -->
<template>
  <view>
    <!-- 根据是否有子分类数据来决定显示内容 -->
    <template v-if="!hasChildren">
      <!-- 没有子分类数据时，显示 "---分类名称---" 格式，居中显示 -->
      <view class="no-data-box ss-flex ss-col-center ss-row-center ss-p-b-30">
        <view class="no-data-text">---{{ props.data[activeMenu].name }}---</view>
      </view>
    </template>

    <template v-else>
      <!-- 有子分类数据时，显示子分类商品（不居中，紧贴顶部） -->
      <view class="goods-item-box ss-flex ss-flex-wrap ss-p-t-20 ss-p-b-20">
        <view
          class="goods-item"
          v-for="item in props.data[activeMenu].children"
          :key="item.id"
          @tap="
            sheep.$router.go('/pages/goods/list', {
              categoryId: item.id,
            })
          "
        >
          <image class="goods-img" :src="item.picUrl" mode="aspectFill" />
          <view class="ss-p-10">
            <view class="goods-title ss-line-1">{{ item.name }}</view>
          </view>
        </view>
      </view>
    </template>
  </view>
</template>

<script setup>
  import sheep from '@/sheep';
  import { computed } from 'vue';

  const props = defineProps({
    data: {
      type: Object,
      default: () => ({}),
    },
    activeMenu: [Number, String],
  });

  // 计算当前选中分类是否有子分类数据
  const hasChildren = computed(() => {
    const currentCategory = props.data[props.activeMenu];
    return currentCategory &&
           currentCategory.children &&
           currentCategory.children.length > 0;
  });
</script>

<style lang="scss" scoped>
  .no-data-box {
    .no-data-text {
      font-size: 28rpx;
      color: #999999;
      text-align: center;
      font-weight: normal;
    }
  }

  .goods-item {
    width: calc((100% - 20px) / 3);
    margin-right: 10px;
    margin-bottom: 10px;

    &:nth-of-type(3n) {
      margin-right: 0;
    }

    .goods-img {
      width: calc((100vw - 140px) / 3);
      height: calc((100vw - 140px) / 3);
    }

    .goods-title {
      font-size: 26rpx;
      font-weight: bold;
      color: #333333;
      line-height: 40rpx;
      text-align: left !important;
    }

    .goods-price {
      color: $red;
      line-height: 40rpx;
    }
  }
</style>
